<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>宝贝投-P2P平台->运营后台</title>
<!-- links begin -->
<link rel="shortcut icon" href="../favicon.ico" />
<link rel="stylesheet" href="../js/bootstrap-3.3.2-dist/css/bootstrap.css" type="text/css" />
<link rel="stylesheet" href="../css/core.css" type="text/css" />
<link type="text/css" rel="stylesheet" href="../css/account.css" />
<script type="text/javascript" src="../js/jquery/jquery-2.1.3.js"></script>
<script type="text/javascript" src="../js/bootstrap-3.3.2-dist/js/bootstrap.js"></script>
<script type="text/javascript" src="../js/jquery.bootstrap.js"></script>
<!-- links end -->
<script type="text/javascript" src="../js/plugins/jquery.form.js"></script>
<script type="text/javascript" src="../js/plugins/jquery.twbsPagination.min.js"></script>
<script type="text/javascript" src="../js/My97DatePicker/WdatePicker.js" ></script>
<script type="text/javascript" src="../js/common.js"></script>

</head>
<body>
	<div class="container">
		<!-- 网页顶部 begin -->
		<div class="mgr-header"></div>
		<!-- 网页顶部 end -->
		<div class="row">
			<!--左侧菜单栏 begin -->
			<div class="mgr-leftmenu col-sm-3"></div>
			<!--左侧菜单栏 end -->
			<div class="col-sm-9">
				<div class="page-header">
					<h3>登录日志查询</h3>
				</div>
				<form id="searchForm" class="form-inline" method="post" action="http://localhost:8080/system/loginlog/query">
					<div class="form-group">
						<label>时间范围:</label>
						<input type="text" id="beginDate" name="beginDate" class="form-control" style="cursor: pointer; background:#fff;" readonly="true" autocomplete="off" value='' />
					</div>
					<div class="form-group">
						<label>&emsp;至&emsp;</label>
						<input type="text" id="endDate" name="endDate" class="form-control" style="cursor: pointer; background:#fff;" readonly="true" autocomplete="off" value='' />
					</div>
					<div class="form-group">
						<label>&emsp;状态:</label>
						<select class="form-control" name="loginResult" id="loginResult">
							<option value="-1">全部</option>
							<option value="0">登录失败</option>
							<option value="1">登录成功</option>
						</select>
					</div>
					<br /><br />
					<div class="form-group">
						<label>&emsp;用户名:</label>
						<input class="form-control" type="text" id="username" name="username" value=''/>
					</div>
					<div class="form-group">
						<label>&emsp;用户类型:</label>
						<select class="form-control" name="accountType" id="accountType">
							<option value="-1">全部</option>
							<option value="2">运营人员</option>
							<option value="1">普通用户</option>
						</select>
					</div>
					<div class="form-group">
						&emsp;
						<button id="query" type="button" class="btn btn-success"><i class="icon-search"></i> 查询</button>
					</div>
				</form>
				<div class="panel panel-default" style="margin-top:20px;">
					<table id="tblLoginLog" class="table table-striped">
						<thead>
							<tr>
								<th>用户</th>
								<th>登录时间</th>
								<th>登录ip</th>
								<th>登录状态</th>
								<th>用户类型</th>
							</tr>
						</thead>
						<tbody></tbody>
					</table>
					<div id="divPagination" style="text-align: center;">
						<ul id="pagination" class="pagination"></ul>
					</div>
				</div>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript">
// 查询条件对象
let queryObject = new Object();

// 判断用户是否已经登录
let jsonUser = sessionStorage.getItem("admin");
if(!jsonUser) window.location.href = 'login.html';

// 如果用户已经登录，则解析出user对象
let user = JSON.parse(jsonUser);

$(function(){

	// 加载公共顶部模板
	$('.mgr-header').load('tpl-head.html');

	// 加载左侧菜单栏模板
	$('.mgr-leftmenu').load('tpl-leftmenu.html');

    // 时间日期组件
    $("#beginDate").click(function(){
        WdatePicker();
    });

    $("#endDate").click(function(){
        WdatePicker();
    });

    // 初始化查询时间

    // 开始时间(最近30天)
    let beginDate = new Date();
    beginDate.setDate(beginDate.getDate() - 30);

    // 结束时间(今天)
    let endDate = new Date();

    $("#beginDate").val(beginDate.Format('yyyy-MM-dd'));
    $("#endDate").val(endDate.Format('yyyy-MM-dd'));

    // 注册查询按钮事件
    $("#query").click(function(){

        // 获取查询数据
        let beginDate = $("#beginDate").val();
        let endDate = $("#endDate").val();
        let loginResult = $("#loginResult").val();
        let username = $('#username').val();
        let accountType = $("#accountType").val();

        // 封装查询请求数据
        queryObject.beginDate = beginDate + ' 00:00:00';
        queryObject.endDate = endDate + ' 23:59:59';
        queryObject.loginResult = loginResult;
        queryObject.username = username;
        queryObject.accountType = accountType;
        queryObject.currentPage  = 1;

        // 加载'登录日志'数据
        loadLoginLog();

    });// $("#query").click(function());


    // 加载'登录日志'数据
    loadLoginLog();

});// $(function());

/** 加载'登录日志'数据 **/
function loadLoginLog(){

    // 加载'登录日志'数据
    $.post('http://localhost:8080/system/loginlog/query', queryObject, function (result) {

        // 如果返回的数据的响应码不是'成功(200)'
        if(result.code != 200) {
            $.messager.alert(result.msg);
            return;
        }

        // 如果返回的数据响应码为200
        // 就进行表格数据填充
        let pageResult = result.data;


        // 填充表格数据
        fillLoginLogTable( pageResult.listData );

        // 初始化分页插件
        $("#pagination").remove();
        $("#divPagination").append('<ul id="pagination" class="pagination"></ul>');

        $("#pagination").twbsPagination({
            totalPages: pageResult.totalPage,
            visiblePages: 10,
            startPage: pageResult.currentPage,
            first: '首页',
            last: '最后一页',
            prev: '上一页',
            next: '下一页',
            onPageClick:function( event, page ){
                // 加载指定页码数据
                queryObject.currentPage = page;
                loadLoginLog();

            }// onPageClick();

        });// $("#pagination").twbsPagination();

    });// $.post();


}// loadLoginLog();

/** 填充表格数据 **/
function fillLoginLogTable( listData ) {

    // 清空表格数据
    $('#tblLoginLog tbody').empty();

    // 循环构造单元格数据，并进行填充
    for( let i = 0; i < listData.length; i++ ) {

        let loginLog = listData[i];

        let tdUsername = '<td>' + loginLog.username + '</td>';
        let tdLoginTime = '<td>' + loginLog.loginTime + '</td>';
        let tdIp = '<td>' + loginLog.ip + '</td>';

        // 登录状态
        let loginResult = LOGIN_RESULT[loginLog.loginResult];
        let tdLoginResult = '<td>' + loginResult + '</td>';

        // 用户类型
		let accountType = ACCOUNT_TYPE[loginLog.accountType];
		let tdAccountType = '<td>' + accountType + '</td>';

        // 将构造好的单元格数据，填充到表格中
        $('#tblLoginLog tbody').append('<tr>' + tdUsername + tdLoginTime + tdIp + tdLoginResult + tdAccountType + '</tr>');

    }// for();

}// fillLoginLogTable( var listData );

</script>
</html>